package com.baizhiedu.basic.web;

import com.baizhiedu.basic.util.WebApplicationContextUtils;
import com.baizhiedu.basic.service.FighterService;
import org.springframework.context.ApplicationContext;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: robert.song
 * @Date: Created in 2021/8/6
 */
public class FighterServletBasedServletContext extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse response) {
        ServletContext servletContext = this.getServletContext();
        ApplicationContext app = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        FighterService fighterService = (FighterService) app.getBean("fighterService1");
        System.out.println(fighterService.getFighter());
    }
}
